package com.lemon;

import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.thread.ThreadFactoryBuilder;
import cn.hutool.core.thread.ThreadUtil;
import cn.hutool.http.HttpException;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class StudentExcutor {


    ExecutorService executorService = Executors.newFixedThreadPool(5, ThreadFactoryBuilder.create().setNamePrefix("study-pool-").build());

    Map<String,String> baseHeaders = new HashMap<String, String>();

    String url = "http://cjstudent.wust.edu.cn/student/student/coursestudyrecord/adddurationpc";

    String name;

    public StudentExcutor() {
    }

    public StudentExcutor(String name,String cookieData,String edurefurlData) {
//        String cookie = System.getenv("COOKIE");
//        String eduRefUrl = System.getenv("EDUREFURL");
        this.name = name;
        String cookie = cookieData;
        String eduRefUrl = edurefurlData;



        baseHeaders.put("Content-Type", "application/json");
        //baseHeaders.put("Cookie", ".CHINAEDUCLOUD=3e2e30e283d34b52b84020c1061a71fe; _pk_testcookie.103.9215=1; _pk_ses.103.9215=1; _pk_id.103.9215=ea1f746037073437.1617848402.1.1617850058.1617848402.");
        //baseHeaders.put("eduRefUrl", "http://cjstudent.wust.edu.cn/student/videolearning.html#Subpage/StudentVersionVideo?courseVersionId=2184325372331776&teachplanCourseVersionId=1694556623301882890&sign=BCF5AEE19975A641ABF2A7A2067B2E8E&userAccountId=1695891656186789897");
        baseHeaders.put("Cookie",cookie);
        baseHeaders.put("eduRefUrl",eduRefUrl);

        baseHeaders.put("metadataCode", "StudentVersion_Video");
        baseHeaders.put("Referer", "http://cjstudent.wust.edu.cn/student/videolearning.html");
        baseHeaders.put("Origin", "http://cjstudent.wust.edu.cn");
        baseHeaders.put("User-Agent", "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Mobile Safari/537.36");
        baseHeaders.put("X-Requested-With", "XMLHttpRequest");

    }

    public void start(){
//        studyCourse6();
//        studyCourse7();
//        studyCourse8();
//        studyCourse9();
        studyCourse10();
        studyCourse11();
        studyCourse12();
        studyCourse13();
    }

    /**
     * 大学英语（一）
     */
    public void studyCourse1(){
        executorService.execute( () -> {
            String body = "{\"data\":{\"courseVersionId\":\"2184325372331776\",\"studyDuration\":100}}";

            Map<String,String> headers = new HashMap<String,String>();
            headers.put("eduSign", "4541a96d2c8623f4437083a8221d538b");
            headers.put("eduToken", "gzcz7JL");

            while (true){
                ThreadUtil.sleep(10000);
                try {
                    HttpResponse execute = HttpUtil.createPost(url).addHeaders(baseHeaders).addHeaders(headers).body(body).execute();
                    System.out.println("大学英语（一） Response  >>>> " + execute.body().toString());
                } catch (HttpException e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * 思想道德修养与法律基础
     */
    public void studyCourse2(){
        executorService.execute( () -> {
            String body = "{\"data\":{\"courseVersionId\":\"1605483291200192520\",\"studyDuration\":30}}";

            Map<String,String> headers = new HashMap<String,String>();
            headers.put("eduSign", "b7362e496292a680fa143e9262e6e4ac");
            headers.put("eduToken", "He0w7JL");

            while (true){
                ThreadUtil.sleep(10000);
                try {
                    HttpResponse execute = HttpUtil.createPost(url).addHeaders(baseHeaders).addHeaders(headers).body(body).execute();
                    System.out.println("思想道德修养与法律基础 Response  >>>> " + execute.body().toString());
                } catch (HttpException e) {
                    e.printStackTrace();
                }
            }

        });
    }

    /**
     * 离散数学
     */
    public void studyCourse3(){
        executorService.execute( () -> {
            String body = "{\"data\":{\"courseVersionId\":\"2184320239667712\",\"studyDuration\":30}}";

            Map<String,String> headers = new HashMap<String,String>();
            headers.put("eduSign", "102021905a9d616ef1d270dbb884407a");
            headers.put("eduToken", "leBL7JL");

            while (true){
                ThreadUtil.sleep(10000);
                try {
                    HttpResponse execute = HttpUtil.createPost(url).addHeaders(baseHeaders).addHeaders(headers).body(body).execute();
                    System.out.println("离散数学 Response  >>>> " + execute.body().toString());
                } catch (HttpException e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * 线性代数与概率统计
     */
    public void studyCourse4(){
        executorService.execute( () -> {
            String body = "{\"data\":{\"courseVersionId\":\"2184320527567360\",\"studyDuration\":30}}";

            Map<String,String> headers = new HashMap<String,String>();
            headers.put("eduSign", "b5a82dfba98bc329e1254c6030ccc329");
            headers.put("eduToken", "ejRT7JL");

            while (true){
                ThreadUtil.sleep(10000);
                try {
                    HttpResponse execute = HttpUtil.createPost(url).addHeaders(baseHeaders).addHeaders(headers).body(body).execute();
                    System.out.println("线性代数与概率统计 Response  >>>> " + execute.body().toString());
                } catch (HttpException e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * 马克思主义基本原理概论
     */
    public void studyCourse5(){
        executorService.execute( () -> {
            String body = "{\"data\":{\"courseVersionId\":\"2184320250628608\",\"studyDuration\":30}}";

            Map<String,String> headers = new HashMap<String,String>();
            headers.put("eduSign", "08d4cbd310e535fa40015565f9890f86");
            headers.put("eduToken", "IAcp7JL");

            while (true){
                ThreadUtil.sleep(10000);
                try {
                    HttpResponse execute = HttpUtil.createPost(url).addHeaders(baseHeaders).addHeaders(headers).body(body).execute();
                    System.out.println("马克思主义基本原理概论 Response  >>>> " + execute.body().toString());
                } catch (HttpException e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * JAVA编程技术
     */
    public void studyCourse6(){
        executorService.execute( () -> {
            String body = "{\"data\":{\"courseVersionId\":\"2184319793580544\",\"studyDuration\":30}}";

            Map<String,String> headers = new HashMap<String,String>();
            headers.put("eduSign", "08d4cbd310e535fa40015565f9890f86");
            headers.put("eduToken", "IAcp7JL");

            while (true){
                ThreadUtil.sleep(10000);
                try {
                    HttpResponse execute = HttpUtil.createPost(url).addHeaders(baseHeaders).addHeaders(headers).body(body).execute();
                    log(name,"JAVA编程技术 Response  >>>> " + execute.body().toString());
                } catch (HttpException e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * 大学英语（二）
     */
    public void studyCourse7(){
        executorService.execute( () -> {
            String body = "{\"data\":{\"courseVersionId\":\"2184325672273920\",\"studyDuration\":30}}";

            Map<String,String> headers = new HashMap<String,String>();
            headers.put("eduSign", "08d4cbd310e535fa40015565f9890f86");
            headers.put("eduToken", "IAcp7JL");

            while (true){
                ThreadUtil.sleep(10000);
                try {
                    HttpResponse execute = HttpUtil.createPost(url).addHeaders(baseHeaders).addHeaders(headers).body(body).execute();
                    log(name,"大学英语（二） Response  >>>> " + execute.body().toString());
                } catch (HttpException e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * 数据结构
     */
    public void studyCourse8(){
        executorService.execute( () -> {
            String body = "{\"data\":{\"courseVersionId\":\"2184320434440704\",\"studyDuration\":30}}";

            Map<String,String> headers = new HashMap<String,String>();
            headers.put("eduSign", "08d4cbd310e535fa40015565f9890f86");
            headers.put("eduToken", "IAcp7JL");

            while (true){
                ThreadUtil.sleep(10000);
                try {
                    HttpResponse execute = HttpUtil.createPost(url).addHeaders(baseHeaders).addHeaders(headers).body(body).execute();
                    log(name,"数据结构 Response  >>>> " + execute.body().toString());
                } catch (HttpException e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * 编译原理
     */
    public void studyCourse9(){
        executorService.execute( () -> {
            String body = "{\"data\":{\"courseVersionId\":\"2184319831362048\",\"studyDuration\":30}}";

            Map<String,String> headers = new HashMap<String,String>();
            headers.put("eduSign", "08d4cbd310e535fa40015565f9890f86");
            headers.put("eduToken", "IAcp7JL");

            while (true){
                ThreadUtil.sleep(10000);
                try {
                    HttpResponse execute = HttpUtil.createPost(url).addHeaders(baseHeaders).addHeaders(headers).body(body).execute();
                    log(name,"编译原理 Response  >>>> " + execute.body().toString());
                } catch (HttpException e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * 操作系统
     */
    public void studyCourse10(){
        executorService.execute( () -> {
            String body = "{\"data\":{\"courseVersionId\":\"2184319912151552\",\"studyDuration\":30}}";

            Map<String,String> headers = new HashMap<String,String>();
            headers.put("eduSign", "08d4cbd310e535fa40015565f9890f86");
            headers.put("eduToken", "IAcp7JL");

            while (true){
                ThreadUtil.sleep(10000);
                try {
                    HttpResponse execute = HttpUtil.createPost(url).addHeaders(baseHeaders).addHeaders(headers).body(body).execute();
                    log(name,"操作系统 Response  >>>> " + execute.body().toString());
                } catch (HttpException e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * 数值计算基础
     */
    public void studyCourse11(){
        executorService.execute( () -> {
            String body = "{\"data\":{\"courseVersionId\":\"2184320438815232\",\"studyDuration\":30}}";

            Map<String,String> headers = new HashMap<String,String>();
            headers.put("eduSign", "08d4cbd310e535fa40015565f9890f86");
            headers.put("eduToken", "IAcp7JL");

            while (true){
                ThreadUtil.sleep(10000);
                try {
                    HttpResponse execute = HttpUtil.createPost(url).addHeaders(baseHeaders).addHeaders(headers).body(body).execute();
                    log(name,"数值计算基础 Response  >>>> " + execute.body().toString());
                } catch (HttpException e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * 数据库系统原理
     */
    public void studyCourse12(){
        executorService.execute( () -> {
            String body = "{\"data\":{\"courseVersionId\":\"2184320435931648\",\"studyDuration\":30}}";

            Map<String,String> headers = new HashMap<String,String>();
            headers.put("eduSign", "08d4cbd310e535fa40015565f9890f86");
            headers.put("eduToken", "IAcp7JL");

            while (true){
                ThreadUtil.sleep(10000);
                try {
                    HttpResponse execute = HttpUtil.createPost(url).addHeaders(baseHeaders).addHeaders(headers).body(body).execute();
                    log(name,"数据库系统原理 Response  >>>> " + execute.body().toString());
                } catch (HttpException e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * 软件工程
     */
    public void studyCourse13(){
        executorService.execute( () -> {
            String body = "{\"data\":{\"courseVersionId\":\"2184320327977472\",\"studyDuration\":30}}";

            Map<String,String> headers = new HashMap<String,String>();
            headers.put("eduSign", "08d4cbd310e535fa40015565f9890f86");
            headers.put("eduToken", "IAcp7JL");

            while (true){
                ThreadUtil.sleep(10000);
                try {
                    HttpResponse execute = HttpUtil.createPost(url).addHeaders(baseHeaders).addHeaders(headers).body(body).execute();
                    log(name,"软件工程 Response  >>>> " + execute.body().toString());
                } catch (HttpException e) {
                    e.printStackTrace();
                }
            }
        });
    }



    public void log(String name,String subject){
        String date = DateUtil.format(new Date(), "yyyy-MM-dd hh:mm:ss");
        System.out.println(String.format("%s %s 续一秒 %s ",date,name,subject));
    }
}
